#include<bits/stdc++.h>
using namespace std;
const int NN=8004;
int a[NN],p[NN];
int main()
{
	freopen("build.in","r",stdin);
	freopen("build.out","w",stdout);
	int n;
	scanf("%d",&n);
	for(int i=1;i<=n;i++)
	{
		scanf("%d",&a[i]);
		p[i]=i;
	}
	int ans=1e9;
	do
	{
		bool flag=true;
		for(int i=1;i<=n;i++)
		{
			int minn=n+1,maxx=0;
			for(int j=i;j<=n;j++)
			{
				minn=min(minn,p[j]),maxx=max(maxx,p[j]);
				if(p[i]!=minn&&p[i]!=maxx&&p[j]!=minn&&p[j]!=maxx)
				{
					flag=false;
					break;
				}
			}
			if(!flag)
				break;
		}
		if(flag)
		{
			int cnt=0;
			for(int i=1;i<=n;i++)
				cnt+=a[i]!=p[i];
			ans=min(ans,cnt);
		}
	}while(next_permutation(p+1,p+1+n));
	printf("%d",ans);
	return 0;
}
